package com.briup.corejava.day14;



import com.briup.corejava.day11.pojo.Student;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.TreeMap;

/**
 * 泛型类测试
 */
public class Test1 {
    public static void main(String[] args) {
        Circle<Integer, Integer> c1 = new Circle<>(0,0);
        c1.setRadius(4);
        c1.run(2);
        c1.show();
        Circle<Double, String> c2 = new Circle<>(2.3,9.3);
        c2.setRadius("4");
        c2.run(2.0);
        c2.show();

        Collection<?> coll = new ArrayList<String>();
        coll.add(null);
        Map<Student,String> map = new TreeMap<>();
        map.put(new Student("aa",20),"21");
    }
}
// 泛型接口
interface Action<T>{
    void run(T t);
}
class
Circle<T,E> implements Action<T>{

    @FirstAnno(value="x变量",type = {"1","2"})
    private T x;
    private T y;
    private E radius;

    public Circle(T x, T y){
        this.x = x;
        this.y = y;
    }
    @FirstAnno(value = "show方法")
    public void show(){
        System.out.println("("+x+","+y+")");
    }

    public void setRadius(E radius) {
        this.radius = radius;
    }

    @Override
    public void run(T o) {
        if(o instanceof Integer && radius instanceof Integer){
            Integer n1 = (Integer) o;
            Integer n2 = (Integer) radius;
            System.out.println(n1*n1*n2);
        }else {
            System.out.println(o);
            System.out.println(radius);
        }
    }
}
